package huoye.shops.huoye.operation.presenter;

import android.util.Log;
import android.view.View;

import com.codeideology.android.lang.entity.Paging;

import java.util.Iterator;
import java.util.List;

import huoye.shops.base.BasePresenter;
import huoye.shops.base.MineBaseJsonRequestCallback;
import huoye.shops.huoye.mine.model.PostDepositRec;
import huoye.shops.huoye.mine.networt.MineService;
import huoye.shops.huoye.mine.view.IRecordPayRefreshView;
import huoye.shops.huoye.operation.model.ShopPrizeList;
import huoye.shops.huoye.operation.networt.OperationService;
import huoye.shops.huoye.operation.view.IManagePrizeRefreshView;

import static huoye.shops.huoye.operation.activity.ManagePrizeActivity.EXTRAS_KEY_PRIZE_SELECT;


/**
 * Created by uesr on 2017/7/19.
 */

public class ManagePrizePresenter extends BasePresenter<IManagePrizeRefreshView> {

    OperationService mService;

    //获取商家奖品列表
    public void getPrizeList(String seek,final Paging paging,final String type){
        // view.showProcessingIndicator();
        mService.getPrizeList(seek,type,paging, new MineBaseJsonRequestCallback<ShopPrizeList>(ShopPrizeList.class) {

            @Override
            public void onSuccess(List<ShopPrizeList> list) {
                super.onSuccess(list);
                if(type.equals(EXTRAS_KEY_PRIZE_SELECT)){
                    //选择奖品
                    Iterator<ShopPrizeList> it = list.iterator();
                    while (it.hasNext()){
                        ShopPrizeList next = it.next();
                        if(next.getiState() == 0){
                            it.remove();
                        }
                    }
                    view.setDataSet(list,paging);
                }else {
                   //奖品管理
                    view.setDataSet(list,paging);
                }





            }

            //网络请求失败
            @Override
            public void onFailure(String msg, String code, Throwable e) {
                super.onFailure(msg, code, e);
                view.makeToast(msg);
            }

            //加载结束
            @Override
            public void onNetworkFail() {
                super.onNetworkFail();
                view.onNetworkFail();
            }

            //加载中
            @Override
            public void onFinish() {
                super.onFinish();
                view.hideProcessingIndicator();
            }
        });
    }



    @Override
    public void onStart() {
        mService = new OperationService();
    }
}
